<template>
  <div class="home">
    <div class="header-nav">
      <input type="text" placeholder="搜索商品，发现更多优选" />
    </div>
     <div class="swiper-container">
      <div class="swiper-wrapper">
        <div
          class="swiper-slide"
          v-for="banner in banners"
          :key="banner.id"
        >
          <img  :src="banner.imageUrl" alt="">
        </div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>

      <!-- 如果需要导航按钮 -->
      <div class="swiper-button-prev"></div>
      <div class="swiper-button-next"></div>
    </div>
    <!-- 列表 -->
    <ul>
      <li
      v-for="prod in list"
      :key="prod.id"
      ></li>
    </ul>
  </div>
</template>

<script>
import { getBanners, getList } from '@/api/home'
import Swiper from 'swiper'
import 'swiper/swiper.scss'
export default {
  name: 'Home',
  data() {
    return {
      banners: [],
      list: []
    }
  },
  created() {
    getBanners().then(res => {
      console.log(res)
      this.banners = res
      this.$nextTick(() => {
        /* eslint-disable-next-line */
        new Swiper ('.swiper-container', {
          autoplay: true, // 自动轮播
          loop: true, // 循环模式选项

          // 如果需要分页器
          pagination: {
            el: '.swiper-pagination'
          },
          // 如果需要前进后退按钮
          navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev'
          }
        })
      })
    })
    getList().then(res => {
      console.log(res)
      this.list = res
    })
  }
}
</script>

<style lang="scss" scoped>
.home{
  width: 100%;
  .header-nav{
  width: 100%;
  height: 50px;
  margin-top: -60px;
  background-color: #fdde4a;
  input{
    width: 327px;
    height:30px;
    margin-top: 8px;
    margin-left: 20px;
    border: none;
    border-radius: 20px;
    font-size: 13px;
    color: #877a73;
    padding-left: 10px;
  }
}
 .swiper-container {
    width: 100%;
    padding-top: calc(100% * 378 / 1008);
    position: relative;
    .swiper-wrapper{
      position: absolute;
      top:0;
      left: 0;
      right: 0;
      bottom: 0;
      img{
        width: 100%;
        height: 100%;
      }
    }
  }
}
</style>
